/*
 * @Descripttion: JsonP请求 用于进行跨域请求
 * @version: 1.0.0
 * @Author: 某人
 * @Date: 2021-05-21 10:30:17
 */
const jsonp = ({url, params, callbackName}) => {
  const generateUrl = () => {
    let dataSrc = ''
    for (let key in params) {
      if (params.hasOwnProperty(key)) {
        dataSrc+=`${key}${params[key]}`
      }
    }
    dataSrc += `callback=${callbackName}`
    return `${url}?${dataSrc}`
  }
  return new Promise((resolve, reject) => {
    const scriptElt = document.createElement('script')
    scriptElt.src = generateUrl()
    document.body.appendChild(scriptElt)
    window[callbackName] = data => {
      resolve(data)
      document.removeChild(scriptElt)
    }
  })
}